package com.tlibrary.service;

import com.tlibrary.dao.UserMapper;
import com.tlibrary.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Author：wcc
 * @Description：
 * @Date：Create in: 2019/1/7--11:17
 */
@Service
public class LogInService {

   @Autowired
   private UserMapper um;

    public String login(User user, HttpServletRequest request, HttpServletResponse response) {
        User msg = um.getUser(user);
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        //使用request对象的getSession()获取session，如果session不存在则创建一个
        HttpSession session = request.getSession();
        session.setAttribute("username",msg.getUsername());
        session.setAttribute("id",msg.getId());
        return msg.getType();
    }
}
